package com.ctshk.common.utils;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @BelongsProject: ctshk-cloud
 * @BelongsPackage: com.ctshk.common.utils
 * @Author: hef
 * @CreateTime: 2021-05-11 14:40
 * @Description: 描述
 */
@Slf4j
public class RequestUtil {

    public static Map<String,Object> getBody(HttpServletRequest request) {
        Map<String, Object> params = new HashMap<String, Object>();
        BufferedReader br;
        try {
            br = request.getReader();
            String str, wholeStr = "";
            while ((str = br.readLine()) != null) {
                wholeStr += str;
            }
            if (StringUtils.isNotEmpty(wholeStr)) {
                params = JSON.parseObject(wholeStr, Map.class);
            }
        } catch (IOException e1) {
            log.error(e1.getMessage());
        }
        return params;
    }
}
